
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module index
* @author: Hjava
* @description: 直播模块，目前由于无业务更新，因此没有引入到SDK中（美团直播、点评直播使用）
* @since: 2018-07-21 17:01:35
*/
var eventEmitter_1 = __webpack_require__(/*! _util/eventEmitter */ "./src/core/utils/eventEmitter.ts");
var cr_constant_1 = __webpack_require__(/*! _chatroom/cr.constant */ "./src/core/chatroom/cr.constant.ts");
var cr_session_1 = __webpack_require__(/*! _chatroom/cr.session */ "./src/core/chatroom/cr.session.ts");
var cr_message_1 = __webpack_require__(/*! _chatroom/cr.message */ "./src/core/chatroom/cr.message.ts");
var userData_1 = __webpack_require__(/*! _util/userData */ "./src/core/utils/userData.ts");
var constant_1 = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var log_1 = __webpack_require__(/*! ./../utils/log */ "./src/core/utils/log.ts");
var CRSDK = /** @class */ (function () {
    function CRSDK(loginSDK) {
        this._loginSDK = null;
        this.constant = cr_constant_1.default;
        this._loginSDK = loginSDK;
        eventEmitter_1.default.on(cr_constant_1.default.CR.URI_CR_SEND_MSG, this._onMessage.bind(this));
        eventEmitter_1.default.on(cr_constant_1.default.CR.URI_CR_SEND_MSG_RES, this._onAck.bind(this));
        eventEmitter_1.default.on(cr_constant_1.default.CR.URI_CR_NOTICE, this._onNotice.bind(this));
    }
    CRSDK.prototype.sendText = function (_a) {
        var _b = _a.fromName, fromName = _b === void 0 ? '' : _b, _c = _a.fromUid, fromUid = _c === void 0 ? userData_1.default.get('uid') : _c, _d = _a.crId, crId = _d === void 0 ? '' : _d, _e = _a.priority, priority = _e === void 0 ? 10 : _e, _f = _a.body.text, text = _f === void 0 ? '' : _f;
        if (text) {
            var message = new cr_message_1.default.CRTextMessage({ text: text });
            return this._sendMessage({
                fromName: fromName,
                fromUid: fromUid,
                crId: crId,
                priority: priority,
                type: constant_1.CR_MESSAGE_TYPE.CR_MSG_TYPE_TEXT,
                message: message
            });
        }
        return null;
    };
    CRSDK.prototype.sendFace = function (_a) {
        var _b = _a.fromName, fromName = _b === void 0 ? '' : _b, _c = _a.fromUid, fromUid = _c === void 0 ? userData_1.default.get('uid') : _c, _d = _a.crId, crId = _d === void 0 ? '' : _d, _e = _a.priority, priority = _e === void 0 ? 10 : _e, _f = _a.body, _g = _f.category, category = _g === void 0 ? '' : _g, _h = _f.type, type = _h === void 0 ? '' : _h, _j = _f.name, name = _j === void 0 ? '' : _j;
        if (category && type && name) {
            var message = new cr_message_1.default.CRFaceMessage({ category: category, type: type, name: name });
            return this._sendMessage({
                fromName: fromName,
                fromUid: fromUid,
                crId: crId,
                priority: priority,
                type: constant_1.CR_MESSAGE_TYPE.CR_MSG_TYPE_FACE,
                message: message
            });
        }
        return null;
    };
    CRSDK.prototype.sendLike = function (_a) {
        var _b = _a.fromName, fromName = _b === void 0 ? '' : _b, _c = _a.fromUid, fromUid = _c === void 0 ? userData_1.default.get('uid') : _c, _d = _a.crId, crId = _d === void 0 ? '' : _d, _e = _a.priority, priority = _e === void 0 ? 10 : _e, _f = _a.body.times, times = _f === void 0 ? 0 : _f;
        if (times) {
            var message = new cr_message_1.default.CRLikeMessage({ times: times });
            return this._sendMessage({
                fromName: fromName,
                fromUid: fromUid,
                crId: crId,
                priority: priority,
                type: constant_1.CR_MESSAGE_TYPE.CR_MSG_TYPE_LIKE,
                message: message
            });
        }
        return null;
    };
    CRSDK.prototype.sendCustom = function (_a) {
        var _b = _a.fromName, fromName = _b === void 0 ? '' : _b, _c = _a.fromUid, fromUid = _c === void 0 ? userData_1.default.get('uid') : _c, _d = _a.crId, crId = _d === void 0 ? '' : _d, _e = _a.priority, priority = _e === void 0 ? 10 : _e, _f = _a.body.data, data = _f === void 0 ? '' : _f;
        if (data) {
            var message = new cr_message_1.default.CRCustomMessage({ data: data });
            return this._sendMessage({
                fromName: fromName,
                fromUid: fromUid,
                crId: crId,
                priority: priority,
                type: constant_1.CR_MESSAGE_TYPE.CR_MSG_TYPE_CUSTOM,
                message: message
            });
        }
        return null;
    };
    CRSDK.prototype._sendMessage = function (_a) {
        var _b = _a.fromName, fromName = _b === void 0 ? '' : _b, _c = _a.fromUid, fromUid = _c === void 0 ? userData_1.default.get('uid') : _c, _d = _a.crId, crId = _d === void 0 ? '' : _d, _e = _a.priority, priority = _e === void 0 ? 10 : _e, type = _a.type, message = _a.message;
        var request = new cr_session_1.default.CRSendReq({
            fromName: fromName,
            fromUid: fromUid,
            crId: crId,
            priority: priority,
            type: type,
            message: message
        });
        this._send(request);
        return this._createMsg(request);
    };
    /**
     * 发送聊天室消息
     * @param message 消息
     */
    CRSDK.prototype._send = function (message) {
        try {
            this._loginSDK._sendTransUp(cr_constant_1.default.SVID_CHATROOM, message);
        }
        catch (e) {
            log_1.default.error(e);
        }
    };
    /**
     * 接受聊天室消息
     * @param message 消息
     */
    CRSDK.prototype._onMessage = function (message) {
        eventEmitter_1.default.emit(constant_1.MESSAGE_EVENT.MESSAGE, this._createMsg(message));
    };
    CRSDK.prototype._createMsg = function (msgData) {
        var result = {
            crId: msgData.crId,
            cts: msgData.cts,
            fromName: msgData.fromName,
            fromUid: msgData.fromUid,
            mid: msgData.mid,
            uuid: msgData.uuid,
            type: msgData.type,
            extension: msgData.extension,
            priority: msgData.priority,
            body: msgData.message
        };
        return result;
    };
    /**
     * 接受ACK
     * @param message 消息
     * @return {*}
     * @private
     */
    CRSDK.prototype._onAck = function (message) {
        eventEmitter_1.default.emit('ack', {
            mid: message.msgId,
            msgUuid: message.uuid,
            cts: message.cts,
            deviceType: message.deviceType,
            rescode: message.rescode
        });
    };
    /**
     * 接受通知消息
     * @param message 消息
     * @private
     */
    CRSDK.prototype._onNotice = function (message) {
        eventEmitter_1.default.emit('notice', message);
    };
    CRSDK.Session = cr_session_1.default;
    CRSDK.Message = cr_message_1.default;
    CRSDK.constant = cr_constant_1.default;
    return CRSDK;
}());
exports.default = CRSDK;


//# sourceURL=webpack://MTDX/./src/core/chatroom/index.ts?